import createElement from "./createElement";
import updateChildren from "./updateChildren";

export default function patchVnode (oldVnode,newVnode){
    // newVnode有text属性，没有子节点
    if(newVnode.text && (newVnode.children === undefined || newVnode.children.length === 0)){
        // 改变dom(oldVnode.elm是要改变的dom元素)
        if(oldVnode.text !== newVnode.text){
            oldVnode.elm.innerText = newVnode.text
        }
    }else if(newVnode.text === undefined && (newVnode.children!=undefined||newVnode.children.length > 0)){
        // 新节点有子节点，但是老节点没有子节点
        if(oldVnode.children == undefined||oldVnode.children.length === 0){
            oldVnode.elm.innerText = ''
            console.log('111',oldVnode.elm)
            for (let i = 0;i<newVnode.children.length;i++){
                oldVnode.elm.appendChild(createElement(newVnode.children[i]))
            }
        }else{
            // 新节点有子节点，老节点也有子节点
            updateChildren(oldVnode.elm,oldVnode.children,newVnode.children)

        }
    }
}
